using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UI;

public class InteractiveObject : MonoBehaviour
{
    public GameObject interactTip; // 用于显示交互提示的UI文本
    private bool playerInRange = false; // 标记玩家是否在范围内

    void Start()
    {
    }

    void Update()
    {
        if (playerInRange && Input.GetKeyDown(KeyCode.E))
        {
            Interact();
        }
    }

    void OnTriggerEnter2D(Collider2D other)
    {
        if (!other.CompareTag("Player")) return;
        playerInRange = true;
        interactTip.SetActive(true);
    }

    void OnTriggerExit2D(Collider2D other)
    {
        if (!other.CompareTag("Player")) return;
        playerInRange = false;
        interactTip.SetActive(false);
    }

    protected virtual void Interact()
    {
        Debug.Log("与物体交互");
        // 这里可以添加具体的交互逻辑，比如打开门或开始对话
    }
}